<template>
  <div id="user-manage">
    <el-container class="home">
      <el-header>
        <span>电商管理系统</span>
        <el-button type="info" @click="logout">退出</el-button></el-header
      >
      <el-container>
        <el-aside :width="this.isCollapse ? '64px' : '200px'">
          <div class="q" @click="toggle">|||</div>
          <el-menu
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            unique-opened
            :collapse="this.isCollapse"
            :collapse-transition="false"
            router
            :default-active="this.activePath"
          >
            <el-submenu
              :index="item.id + ''"
              v-for="item in menulist"
              :key="item.id"
            >
              <template slot="title">
                <i :class="iconsObject[item.id]"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item
                :index="'/' + subItem.path"
                v-for="subItem in item.children"
                :key="subItem.id"
                @click="SaveNavState('/' + subItem.path)"
              >
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{ subItem.authName }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      menulist: [],
      iconsObject: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      isCollapse: false,
      activePath: "",
    };
  },
  created() {
     console.log('2222')
    this.getMenuList();
    this.activePath = window.sessionStorage.getItem("activePath");
      console.log("sbs"+this.activePath)
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      setTimeout(() => {
        this.$router.push("/login");
      }, 1 * 1000);
    },
    async getMenuList() {
      const { data: res } = await this.$http.get("menus");
      if (res.meta.status != 200) return this.$message.error(res.meta.msg);
      this.menulist = res.data;
    },
    toggle() {
      this.isCollapse = !this.isCollapse;
    },
    SaveNavState(Path) {
      window.sessionStorage.setItem("activePath", Path);
      this.activePath = Path;
    },
  },
};
</script>
<style lang="less" scoped>
#user-manage {
  height: 100%;
  .home {
    height: 100%;
  }
  .el-header{
    background-color: #b3c0d1;
    color: #333;
    padding-left: 2%;
    align-items: center;
    justify-content: space-between;
    font-size: 20px;
    display: flex;
  }

  .el-aside {
   background-color: #545c64;
    color: #333;
    line-height: 200px;
    .el-menu {
      border-right: none;
    }
  }
  .iconfont {
    margin-right: 20px;
  }
  .q {
    background-color: #333;
    font-size: 10px;
    line-height: 24px;
    color: rgb(243, 232, 232);
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
  // .el-main {
  //   background-color: #9ea4aa;
  // }
  //   .el-header{
  //   background-color: rgb(78, 72, 72);
  // }
  // .el-aside{
  //    background-color:rgb(78, 72, 72);
  // }
  // .el-main{
  //   background-color: aliceblue;
  // }
}
</style>